package com.itheima.controller;

import com.itheima.bean.pojo.Role;
import com.itheima.bean.vo.Code;
import com.itheima.bean.vo.Result;
import com.itheima.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    //查询所有角色
    @CrossOrigin  //允许跨域
    @GetMapping  //获取数据的时候用GetMapping  提交数据的时候用PostMapping
    public Result selectAllRole() {
        //调用业务层：查询所有角色
        List<Role> roleList = roleService.queryRoles();
         //创建响应结果对象
        Result responseResult = new Result(Code.GET_ERR, "查询失败");
        if(roleList!=null&&!roleList.isEmpty()){
            responseResult=new Result(Code.GET_OK,roleList,"查询成功");
        }
        return responseResult;
    }
}
